using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;using THSERP.BusinessEntities;using THSERP.BaseProvider;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace THSERP.Modules.BranchStatistics
{
    public partial class guiRedemptionInventoryStatistics : THSERPScreen
    {
        public guiRedemptionInventoryStatistics()
        {
            InitializeComponent();
        }

        private void fld_btnGetRedemptionInventory_Click(object sender, EventArgs e)
        {
            ICInventoryStockSerialsController objInventoryStockSerialsController = new ICInventoryStockSerialsController();
            ICStocksInfo objRedemptionStockInfo = new ICStocksController().GetRedemptionStock();
            DataSet ds = objInventoryStockSerialsController.GetAllDataByForeignColumn("FK_ICStockID", objRedemptionStockInfo.ICStockID);
            if (ds.Tables.Count > 0)
            {
                ICProductsController objProductsController = new ICProductsController();

                ds.Tables[0].Columns.Add("ICInventoryStockSerialProductNo", typeof(string));
                foreach (DataRow row in ds.Tables[0].Rows)
                {
                    ICInventoryStockSerialsInfo objInventoryStockSerialsInfo = (ICInventoryStockSerialsInfo)objInventoryStockSerialsController.GetObjectFromDataRow(row);
                    if (objInventoryStockSerialsInfo != null)
                    {
                        int iProductID = Convert.ToInt32(row["FK_ICProductID"]);
                        String strProductNo = String.Empty;
                        String strProductSerialNo = String.Empty;
                        String[] arr = row["ICInventoryStockSerialProductSerialNo"].ToString().Split('*');

                        ICProductsInfo objProductsInfo = (ICProductsInfo)objProductsController.GetObjectByID(iProductID);
                        if (objProductsInfo != null)
                             strProductNo = objProductsInfo.ICProductNo;
                        else
                            if (arr.Length > 1)
                                strProductNo = arr[1];

                        if (arr.Length > 0)
                            strProductSerialNo = arr[0];

                        row["ICInventoryStockSerialProductNo"] = strProductNo;
                        row["ICInventoryStockSerialProductSerialNo"] = strProductSerialNo;
                    }
                }
                fld_dgcRedemptionInventory.DataSource = ds.Tables[0];
            }
        }

        private void guiRedemptionInventoryStatistics_Load(object sender, EventArgs e)
        {
            if (!THSApp.CurrentUserGroupInfo.ADUserGroupName.Contains("ADMIN"))
                this.Visible = false;
        }

        private void guiRedemptionInventoryStatistics_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
                fld_btnGetRedemptionInventory_Click(new object(), new EventArgs());
        }
    }
}